package com.pj.app.auraSimulator;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

public class FileChooser extends JFileChooser{
	private int returnValue; 
	private Controller c;
	public FileChooser(Controller controller) {
		super();
		this.c = controller;
		this.setCurrentDirectory(new File(System.getProperty("user.dir")));
		this.setFileFilter(new FileFilter() {
			
			@Override
			public String getDescription() {
				// TODO Auto-generated method stub
				return null;
			}
			
			@Override
			public boolean accept(File f) {
				if (f.isDirectory()) {
					return true;
				}
				String extension = Utils.getExtension(f);
				if(extension != null) {
					if(extension.equals("xml"))
						return true;
					else 
						return false;
				}
				return false;
			}
		});
	}
	public void open() {
		returnValue = this.showOpenDialog(null);
		if(returnValue == JFileChooser.APPROVE_OPTION) {
			c.fileSelectedEvent(this.getSelectedFile());
		}
	}
}
